package poker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import java.awt.Font;

import javax.swing.JSlider;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import java.awt.Color;

import javax.swing.JTextArea;
 
public class GetParametsGUI extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GetParametsGUI frame = new GetParametsGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/*  @Override
	    public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        int w2 = getWidth() / 2;
	        int h2 = getHeight() / 2;
	        g2d.rotate(-Math.PI / 2, w2, h2);
	        super.paintComponent(g);
	    }*/
	/**
	 * Create the frame.
	 */
	public GetParametsGUI() {
		super("Wczytajmy dane");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setBounds(100, 100, 450, 300);
		
		/*	Number Of Players */
		
		JLabel NumberOfPlayers = new JLabel("Number of Players");
		NumberOfPlayers.setFont(new Font("Tahoma", Font.BOLD, 13));
		NumberOfPlayers.setBounds(15, 10, 125, 30);
		getContentPane().add(NumberOfPlayers);
		
		final JSlider slider_NoP = new JSlider();
		slider_NoP.setMinimum(2);
		slider_NoP.setValue(4);
		slider_NoP.setMaximum(4);
		slider_NoP.setBounds(140, 10, 200, 30);
	
		
		final JTextField actualNoP = new JTextField(""+slider_NoP.getValue());
		actualNoP.setBackground(new Color(240, 240, 240));
		actualNoP.setFont(new Font("Tahoma", Font.BOLD, 13));
		actualNoP.setBounds(350, 10, 30, 30);
	   getContentPane().add(actualNoP);
	    getContentPane().add(slider_NoP);
		
	    /*	Number Of Humans */
		JLabel NumberOfHumans = new JLabel("Number of Humans");
		NumberOfHumans.setFont(new Font("Tahoma", Font.BOLD, 13));
		NumberOfHumans.setBounds(15, 60, 125, 30);
		getContentPane().add(NumberOfHumans);
		
		final JSlider slider_NoH = new JSlider();
		slider_NoH.setMinimum(0);
		slider_NoH.setValue(4);
		slider_NoH.setMaximum(4);
		slider_NoH.setBounds(140, 60, 200, 30);
		
		final JTextField actualNoH = new JTextField(""+slider_NoH.getValue());
		actualNoH.setBackground(new Color(240, 240, 240));
		actualNoH.setFont(new Font("Tahoma", Font.BOLD, 13));
		actualNoH.setBounds(350, 60, 30, 30);
		getContentPane().add(actualNoH);
		getContentPane().add(slider_NoH);
		
		/*	Chips on start the game */
		JLabel ChipsOnStart = new JLabel("Chips on start");
		ChipsOnStart.setFont(new Font("Tahoma", Font.BOLD, 13));
		ChipsOnStart.setBounds(15, 110, 125, 30);
		contentPane.add(ChipsOnStart);
		
		final JSlider slider_Cos = new JSlider();
		slider_Cos.setMinimum(2);
		slider_Cos.setValue(200);
		slider_Cos.setMaximum(999);
		slider_Cos.setBounds(140, 110, 200, 30);
		
		
		final JTextField actualCos = new JTextField(""+slider_Cos.getValue());
		actualCos.setBackground(new Color(240, 240, 240));
		actualCos.setFont(new Font("Tahoma", Font.BOLD, 13));
		actualCos.setBounds(350, 110, 30, 30);
		getContentPane().add(actualCos);
		getContentPane().add(slider_Cos);
		
		/*	Entry Fee */
		JLabel EntryFee = new JLabel("Entry Fee");
		EntryFee.setFont(new Font("Tahoma", Font.BOLD, 13));
		EntryFee.setBounds(15, 160, 125, 30);
		contentPane.add(EntryFee);
		
		final JSlider slider_ef = new JSlider();
		slider_ef.setValue(2);
		slider_ef.setMinimum(1);
		slider_ef.setMaximum(999);
		slider_ef.setBounds(140, 160, 200, 30);
		contentPane.add(slider_ef);
		
		final JTextField actualef = new JTextField(""+slider_ef.getValue());
		actualef.setBackground(new Color(240, 240, 240));
		actualef.setFont(new Font("Tahoma", Font.BOLD, 13));
		actualef.setBounds(350, 160, 30, 30);
		getContentPane().add(actualef);
		getContentPane().add(slider_ef);
		/*	Button start a GAME */

		JButton StartAGame = new JButton("START A GAME");
		StartAGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int NumberOfPlayers1 = Integer.parseInt(actualNoP.getText());
				
				int NumberOfHumans1 = Integer.parseInt(actualNoH.getText());
				
				int NumberOfChips1 = Integer.parseInt(actualCos.getText());
				
				int EntryFee1 = Integer.parseInt(actualef.getText());
	
				TableGui tabela = new TableGui(NumberOfPlayers1,NumberOfHumans1,NumberOfChips1,EntryFee1);
				tabela.setVisible(true);
				tabela.setResizable(false);
				hide();

			
			}
		});
		StartAGame.setBounds(150, 200, 125, 30);
		contentPane.add(StartAGame);
		
		/* Action Listener */
		slider_NoP.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                actualNoP.setText(String.valueOf(slider_NoP.getValue()));
                if (Integer.parseInt(actualNoP.getText())<Integer.parseInt(actualNoH.getText()))
                actualNoH.setText(String.valueOf(slider_NoP.getValue()));
            }
        });
		slider_NoH.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                actualNoH.setText(String.valueOf(slider_NoH.getValue()));
            }
        });
		slider_Cos.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                actualCos.setText(String.valueOf(slider_Cos.getValue()));
            }
        });
		slider_ef.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                actualef.setText(String.valueOf(slider_ef.getValue()));
            }
        });
		actualNoP.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
	     
	            	slider_NoP.setValue(Integer.parseInt(actualNoP.getText()));
	            	if (Integer.parseInt(actualNoP.getText())<Integer.parseInt(actualNoH.getText()))
	            		slider_NoH.setValue(Integer.parseInt(actualNoP.getText()));	
	     
        }
		});
		actualNoH.addActionListener(new ActionListener() {
	        @Override
	        public void actionPerformed(ActionEvent e) {
		           
		            	slider_NoH.setValue(Integer.parseInt(actualNoH.getText()));
		            	if (Integer.parseInt(actualNoP.getText())<Integer.parseInt(actualNoH.getText()))
		            		slider_NoH.setValue(Integer.parseInt(actualNoP.getText()));	
		          
		           
	        }
			});
		actualCos.addActionListener(new ActionListener() {
	        @Override
	        public void actionPerformed(ActionEvent e) {
		           
		            	slider_Cos.setValue(Integer.parseInt(actualCos.getText()));
		            
	        }
			});
		actualef.addActionListener(new ActionListener() {
	        @Override
	        public void actionPerformed(ActionEvent e) {
		            	slider_ef.setValue(Integer.parseInt(actualef.getText()));
		          
	        }
		});
    this.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e){
        }

        @Override
        public void focusGained(FocusEvent e) {
        	actualNoP.setText(String.valueOf(slider_NoP.getValue()));
        	actualNoH.setText(String.valueOf(slider_NoH.getValue()));
        	actualCos.setText(String.valueOf(slider_Cos.getValue()));
        	actualef.setText(String.valueOf(slider_ef.getValue()));
        	
        }
    });
  
	
	}
}
